//
//  XXiListCell.m
//  GuShiNews
//
//  Created by 丁一 on 2019/8/23.
//  Copyright © 2019 Jones. All rights reserved.
//

#import "XXiListCell.h"
#import "XueXiModel.h"

@interface XXiListCell ()

@property (nonatomic, strong) UILabel *Label_tittle;
@property (nonatomic, strong) UILabel *Label_bottom;
@property (nonatomic, strong) CALayer *News_line;

@end

@implementation XXiListCell

+ (instancetype)cellForTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *ID = @"XXiListCell";
    
    XXiListCell  *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell)
    {
        cell = [[XXiListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        
        cell.backgroundColor          = [UIColor whiteColor];

        [cell.contentView.layer addSublayer:cell.News_line];
        [cell.contentView addSubview:cell.Label_tittle];
        [cell.contentView addSubview:cell.Label_bottom];
        [cell.contentView addSubview:cell.Label_o];
        [cell.contentView addSubview:cell.Img];
    }
    
    return cell;
}

- (void)setModel:(XueXiModel *)Model{
    if (_Model != Model) {
        _Model = Model;
    }
    
    NSDictionary *dic = @{NSKernAttributeName:@0.f};
    NSMutableAttributedString * attributedString =     [[NSMutableAttributedString alloc] initWithString:_Model.x_tittle attributes:dic];
    
    NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc]     init];
    [paragraphStyle setLineSpacing:4];
    
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [_Model.x_tittle length])];
    [_Label_tittle setAttributedText:attributedString];
    [_Label_tittle sizeToFit];
    
    _Label_tittle.frame=CGRectMake(20, 20, RECRWITCH-40, 35);
    _Label_bottom.frame=CGRectMake(20, 50, RECRWITCH-40, 50);
    _News_line.frame=CGRectMake(15, 15, RECRWITCH-30, 120);
    
    _Label_o.text = [JonesClass timeZhuan:_Model.x_date];
    _Label_bottom.text = _Model.x_info_string;
    
    
}

-(UIImageView *)Img{
    if (!_Img) {
        _Img                     = [[UIImageView alloc] init];
        _Img.frame=CGRectMake(RECRWITCH-60, 20, 35, 35);
    }
    return _Img;
}

-(UILabel *)Label_tittle{
    if (!_Label_tittle) {
        _Label_tittle           = [[UILabel alloc] init];
        _Label_tittle.font      = [UIFont boldSystemFontOfSize:16];
        _Label_tittle.textColor = NewsTitleColor;
//        _Label_tittle.numberOfLines = 2;
        _Label_tittle.frame=CGRectMake(20, 20, RECRWITCH/3*2-40, 50);
        //        _Label_tittle.lineBreakMode = NSLineBreakByCharWrapping;
    }
    return _Label_tittle;
}

-(UILabel *)Label_bottom{
    if (!_Label_bottom) {
        _Label_bottom           = [[UILabel alloc] init];
        _Label_bottom.font      = [UIFont systemFontOfSize:14];
        _Label_bottom.textColor = [JonesClass stringTOColor:@"#666666"];
        _Label_bottom.frame = CGRectMake(20, 75, _Label_tittle.frame.size.width, 20);
        _Label_bottom.numberOfLines = 3;
    }
    return _Label_bottom;
}

-(UILabel *)Label_o{
    if (!_Label_o) {
        _Label_o           = [[UILabel alloc] init];
        _Label_o.font      = [UIFont systemFontOfSize:13];
        _Label_o.textColor = NewsotherColor;
        _Label_o.frame = CGRectMake(20, 105, _Label_tittle.frame.size.width, 20);
    }
    return _Label_o;
}

- (CALayer *)News_line{
    if (!_News_line) {
        _News_line = [[CALayer alloc] init];
        _News_line.frame=CGRectMake(20, 119, RECRWITCH-40, 0.7);
        _News_line.backgroundColor=LineColor.CGColor;
        _News_line.masksToBounds = YES;
        _News_line.cornerRadius = 10;
    }
    return _News_line;
}
@end
